import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.countAndSay(1));
        System.out.println(s.countAndSay(2));
        System.out.println(s.countAndSay(3));
        System.out.println(s.countAndSay(4));
        System.out.println(s.countAndSay(5));
        System.out.println(s.countAndSay(6));
        System.out.println(s.countAndSay(7));
        System.out.println(s.countAndSay(30));
    }
}


class Solution {
    static class NumCount{
        char digit;
        int count;
        NumCount(char digit, int count){
            this.digit = digit;
            this.count = count;
        }
    }

    public String countAndSay(int n) {
        List<NumCount> numCounts;
        char[] sequence = {'1'};
        for(int i = 2; i <= n; i++){
            numCounts = getNumCounts(sequence);
            sequence = getSequence(numCounts);
        }
        return String.valueOf(sequence);
    }

    List<NumCount> getNumCounts(char[] sequence){
        List<NumCount> numCounts = new ArrayList<>();
        int count = 0;
        for(int i = 0; i < sequence.length; i++){
            if(i < sequence.length - 1 && sequence[i] == sequence[i + 1]){
                count++;
            }
            else{
                count++;
                numCounts.add(new NumCount(sequence[i], count));
                count = 0;
            }
        }
        return numCounts;
    }

    char[] getSequence(List<NumCount> numCounts){
        char[] sequence = new char[numCounts.size() * 2];
        for(int i = 0; i < numCounts.size(); i++){
            sequence[2 * i] = (char)(numCounts.get(i).count + '0');
            sequence[2 * i + 1] = numCounts.get(i).digit;
        }
        return sequence;
    }
}